package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.RechargeDao;
import ysq.xyg.model.Recharge;
import ysq.xyg.service.RechargeService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 购物车
 *
 * @author congcong tao
 * @create 2018/8/9 下午8:52
 */
@Service("rechargeService")
public class RechargeServiceImpl extends BaseServiceImpl<Recharge> implements RechargeService {

    @Resource
    private RechargeDao rechargeDao;
    @Autowired
    public void setRechargeDao(RechargeDao rechargeDao) {
        this.baseDao = rechargeDao;
    }

    @Override
    public PageInfo<Recharge> pageInfo(Recharge recharge, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        // 通用Example查询
        Example example = new Example(Recharge.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(recharge.getMemberId())) {
            criteria.andEqualTo("memberId", recharge.getMemberId());
        }
        example.orderBy("createTime asc");
        List<Recharge> list = rechargeDao.selectByExample(example);
        return new PageInfo<Recharge>(list);
    }
}
